package cn.com.cym.gamezao.web.recruit;


import cn.com.cym.gamezao.annotation.AuthToken;
import cn.com.cym.gamezao.entity.xmu.recruit.WorkExperience;
import cn.com.cym.gamezao.service.recruit.WorkExperienceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.*;

@Api(tags = "r-岗位相关")
@RestController
@RequestMapping(value = "work")
@AuthToken(rule = "recruit.work")
public class WorkExperienceController {
    final WorkExperienceService workExperienceService;

    WorkExperienceController(WorkExperienceService workExperienceService){
        this.workExperienceService = workExperienceService;
    }

    @ApiOperation(value = "查看规培经历！")
    @ApiOperationSupport(order = 1, author = "mr.chen")
    @GetMapping("/list")
    @AuthToken(rule = "list",require = false)
    public ResponseEntity<?> list() {
        return ResponseEntity.ok(workExperienceService.searchByCurrentUser());
    }


    @ApiOperation(value = "新增规培经历！")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @PostMapping("/add")
    @AuthToken(rule = "add",require = false)
    public ResponseEntity<?> add(@RequestBody WorkExperience workExperience){
        return ResponseEntity.ok(this.workExperienceService.save(workExperience));
    }

    @ApiOperation(value = "修改规培经历！")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @PutMapping("/{id}")
    @AuthToken(rule = "add",require = false)
    public ResponseEntity<?> modify(@RequestBody WorkExperience workExperience, @NonNull @PathVariable Long id){
        return ResponseEntity.ok(this.workExperienceService.update(workExperience,id));
    }

    @ApiOperation(value = "删除规培经历！")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @DeleteMapping("/{id}")
    @AuthToken(rule = "modify",require = false)
    public ResponseEntity<?> deleteById(@PathVariable Long id){
        this.workExperienceService.deleteById(id);
        return ResponseEntity.ok().build();
    }
}
